home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRNOMY / SFS101S.ZIP / RO101.ZIP / RO_SETP.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  6KB  |  258 lines

  1. /********************************************************/
  2. /*                            */
  3. /*    ro_setp.c    set parameters and other     */
  4. /*            routines for ro            */
  5. /*                            */
  6. /*    ro version 1.10                    */
  7. /*                            */
  8. /*    Portions copyright (c) 1989 by Ted A. Campbell    */
  9. /*        Bywater Software            */
  10. /*        P. O. Box 4023                */
  11. /*        Duke Station                */
  12. /*        Durham, NC  27706            */
  13. /*                            */
  14. /*    Contains portions of ROFF4, Version 1.60    */
  15. /*      (c) 1983, 4 by Ernest E. Bergmann               */
  16. /*        Physics, Building #16            */
  17. /*        Lehigh University            */
  18. /*        Bethlehem, Pa. 18015            */
  19. /*                            */
  20. /*    Contains portions of ROFF4, Version 1.61    */
  21. /*      (c) 1985 by Konrad Kwok                         */
  22. /*        20 3rd Street, Section M        */
  23. /*        Fariview Park,                */
  24. /*        Hong Kong                */
  25. /*                            */
  26. /*    ro and its predecessor ROFF4 are based on     */
  27. /*    the ROFF text processor described in Kernigan    */
  28. /*    and Plauger's now-classic text <Software Tools> */
  29. /*                            */
  30. /* Permission is hereby granted for all commercial and    */
  31. /* non-commercial reproduction and distribution of this */
  32. /* material provided this notice is included.        */
  33. /*                            */
  34. /********************************************************/
  35.  
  36. #include "ro.h"
  37.  
  38. /**************************************************/
  39.  
  40. int value( base, string)   /*unsigned conversion*/
  41.    int base;         /*radix for conversion*/
  42.    char *string;          /*no leading blanks please!*/
  43.             /*trailing whitespace or '\0'*/
  44.    {
  45.    int val,d;
  46.    char c;
  47.    val=0;
  48.    for(d=digit(*string);d>=0 && d<base ; d=digit(*string))
  49.       {
  50.       val = val*base + d;
  51.       string++;
  52.       }
  53.    c = *string;
  54.    if ( !c || c==' ' || c==TAB || c=='\n') return(val);
  55.    else return(-1);      /*error return is -1*/
  56.    }
  57.  
  58. /**************************************************/
  59.  
  60. int digit(d)
  61. char d;
  62.    {    
  63.    d=toupper(d);
  64.    if(d<='9') return(d-'0');
  65.    if(d<'A') return(-1); /*error return is negative val*/
  66.    if(d<='Z') return(10-'A'+d);
  67.    return(-1);    /*error*/
  68.    }
  69.  
  70. /**************************************************/
  71. /* returns printed string length; checks legality of
  72. word function; keeps track of vertical
  73. excursions; records them in globals */
  74.  
  75. strln3( s, word, num )
  76.    char *s;
  77.    int word;               /* boolean, if true, check is made for none
  78.                 black characters in the string */
  79.    int num;                /* for expansion of NUMSIGN; set 1 to ignore */
  80.    {
  81.    int i, i2;
  82.    int t, b, h;            /*vertical vars*/
  83.    char c, *ss;
  84.    ss = s;
  85.    t = b = h = 0;
  86.    for ( c = *ss, i2 = i = 0; c; c = *(++ss) )
  87.       {
  88.       if ( c == NUMSIGN )
  89.          {
  90.          i++;
  91.          if ( num > 9   ) i++;
  92.          if ( num > 99  ) i++;
  93.          if ( num > 999 ) i++;
  94.          }
  95.       else if ( c == BACKSPACE )
  96.          {
  97.          --i;
  98.          }
  99.       else if ( (c != ro_tcval[0] ) && ( c != ESCAPE ) )
  100.          {
  101.          if ( ( c <= ' ' ) && (word) )
  102.             {
  103.             if ( ro_verbose == TRUE )
  104.                {
  105.                fprintf( stderr, "ro: illegal character 0x%x \n",
  106.                   c );
  107.                }
  108.             goto error;
  109.             }
  110.          else i++;
  111.          }
  112.       else if ( c == ESCAPE )
  113.          {
  114.          c = *(++ss);      
  115.          if ( c == ESCAPE ) 
  116.             {
  117.             goto error; /*both ro_cfval[0], ro_tcval[0] */
  118.             }
  119.          switch( c )
  120.             {
  121.             case ROMAN:
  122.             case ITALIC:
  123.             case BOLD:
  124.             case HALFUP:
  125.             case HALFDOWN:
  126.                break;
  127.             default: 
  128.                if (ro_verbose )
  129.                   {
  130.                   fprintf( stderr, "ro:  c <%c> is not printer code. \n", c );
  131.                   }
  132.                goto error;    /* undecipherable */
  133.                break;
  134.             }
  135.          }
  136.       else         /* c == ro_tcval[ 0 ] */
  137.          {
  138.          if ( class ( *(s+1)) != BLACK )
  139.             {
  140.             goto error;      /*illegal translation*/
  141.             }
  142.          }
  143.       }
  144.    if ( h )
  145.       {
  146.       goto error;
  147.       }
  148.    if ( word )
  149.       {
  150.       ro_wtop=t;
  151.       ro_wbot=b;
  152.       }
  153.    else
  154.       {
  155.       ro_ltop=t;
  156.       ro_lbot=b;
  157.       }
  158.    if(i>=i2)
  159.       {
  160.       return( i );
  161.       }
  162.  
  163.    /* else prints beyond last character: */
  164.  
  165. error:
  166.    if ( ro_verbose == TRUE )
  167.       {
  168.       fprintf( stderr, "ro: line <%s> is illegally formed.\n", s );
  169.       }
  170.  
  171.    return ( strlen( ss ) );
  172.    }
  173.  
  174. /* A properly formed token string has its first printable
  175. character indicating the lefthand edge and the last printable
  176. character at the right hand edge.   Only legal control pairs
  177. accepted.   It must consist of printable symbols. */
  178.  
  179. /**************************************************************
  180. Set a stack variable like set() sets a global integer variable.  
  181. **************************************************************/
  182.  
  183. setS ( param, val, arg_typ, defval, minval, maxval )
  184.    int param[STKSIZ], val, defval, minval, maxval;
  185.    int arg_typ;
  186.    {
  187.    register int i;
  188.  
  189.    if ( val == NO_VAL )
  190.       {
  191.       for ( i = 0; i < STKSIZ - 1; i++ )   /*pop*/
  192.          {
  193.          param[ i ] = param[ i + 1 ];
  194.          }
  195.       param[ STKSIZ - 1 ] = defval;
  196.       }
  197.    else
  198.       {
  199.       for ( i = STKSIZ - 1; i; i-- )   /*push*/
  200.          {
  201.           param[ i ] = param[ i - 1 ];
  202.          }
  203.       if ( arg_typ == '+' ) 
  204.          {
  205.          param[ 0 ] += val;
  206.          }
  207.       else if ( arg_typ == '-' ) 
  208.          {
  209.          param[ 0 ] -= val;
  210.          }
  211.       else param[ 0 ] = val;
  212.       }
  213.    param[ 0 ] = ro_min( ro_max( param[ 0 ], minval), maxval );
  214.  
  215. #ifdef   DEBUG
  216.    if ( ro_debug == TRUE ) 
  217.       {
  218.       fprintf( stderr, "DEBUG:  setS(): *param = %d \n", *param );
  219.       }
  220. #endif
  221.  
  222.    }
  223.  
  224. /******************************************
  225. initialize stack type variable, st, with v
  226. *******************************************/
  227.  
  228. initsk( st, v )
  229.    int st[STKSIZ], v;
  230.    {
  231.    register int i;
  232.    for ( i = STKSIZ - 1; i >= 0; --i )
  233.       {
  234.       st[ i ] = v;
  235.       }
  236.    }
  237.  
  238. /**************************************************/
  239.  
  240. gettr() /*process .tr */
  241.    {
  242.    if ( ro_verbose )
  243.       fprintf( stderr, ".tr is not currently implemented. \n" );
  244.    }
  245.  
  246. /**************************************************/
  247.  
  248. outstr(p)    /*print string whose bytecount is *p */
  249. char *p;
  250.    {
  251.    int i;
  252.    for ( i = *(p++); i; i-- )
  253.       {
  254.       ro_outc( *(p++) );
  255.       }
  256.    }
  257.  
  258.